﻿@using MvcContrib.UI.Grid
@using XRM.Security.WebUI.MvcHelpers
@model XRM.Security.WebUI.Models.UserRegister.UserRegisterListModel
@{
    ViewBag.Title = "Реестр пользователей";
    ViewBag.HideHeader = true;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div>
    <div>
    @using (Html.BeginForm("Filter", "UserRegister", FormMethod.Post, new { @class = "form-horizontal form-horizontal-2", id = "filterForm" }))
    {
        <div class="form-group">
            @Html.LabelFor(m => m.TextFilter, new { @class = "control-label" })
            <div class="control-group">
                    <div class="col-sm-5">
                        <div class="input-group">
                            @Html.TextBoxFor(m => m.TextFilter, new { @class = "form-control", title = "Введите ФИО пользователя, наименование должности или подразделения" })
                            @Html.Partial("ClearButtonPartial")
                        </div>
                    </div>
                    <div class="col-sm-1">
                        <button class="btn btn-primary btn-block" type="submit" id="btnFind">Найти</button>
                    </div>
            </div>
        </div>
        
        <div class="form-group">
                <label class = "control-label">&nbsp;</label>
                <div class="control-group">
                    <div class="col-sm-5">
                        <div class="checkbox">
                            <label for="ShowAllFilter">
                                @Html.CheckBoxFor(x => x.ShowAllFilter)
                                Искать среди уволенных/в длительном отпуске
                            </label>
                        </div>    
                    </div>
                </div>
        </div>
    }
    </div>
    
    <hr/>

    <p class="actions-centered">
        @Html.DialogFormButton(new DialogButtonOptions()
           {
               Text = "Добавить пользователя",
               ContentUrl = Url.Action("ADUsersDialog"),
               Width = "800",
               Id = "dlgADUsersDialog",
               ButtonCss = "btn btn-large btn-primary",
               OnOpen = "SetFocusDialog",
               OnSuccess = "GotoEdit"
           })
    </p>
</div>

    @{
        if (Model.UserList.Any())
        {
            Html.Grid(Model.UserList).Columns(column =>
            {
                column.For(item => Html.ActionLink(item.FullName, "Edit", "UserRegister", new { id = item.Id }, null)).Named("Пользователь")
                    .Attributes( nowrap => "nowrap" );
                column.For(item => item.DepartmentName).Named("Подразделение");
                column.For(item => item.DepartmentAddressName).Named("Адрес");
                column.For(item => item.Post).Named("Должность");
                column.For(item => item.StatusCaption).Named("Статус");
                column.For(item => item.IsADUserCaption).Named("Из AD").Attributes(style => "width: 60px;");

            }).Attributes(@class => "table table-striped table-bordered", id => "table_id")
              .Empty("Нет данных для отображения")
              .Render();
        }
        else if (Model.UserList != null )
        {
            <strong>Пользователи не найдены.</strong>
        }
    }


@section scripts
{
     @Scripts.Render("~/bundles/gridlibrary")

    <script type="text/javascript">
        $(document).ready(function () {
            @if (Model.UserList.Any())
            {
                <text>
                $('#table_id').dataTable({
                    paging: false,
                    bFilter: false,
                    bSort: true,
                    info: false,
                    "order": [[0, "asc"]]
                });
                </text>
            }
        });

        function SetFocusDialog() {
            $('#LastNameFilter').focus();
        }
        function GotoEdit(data) {
            window.location = '@(Url.Action("Edit"))/' + data.userId;
    }
    </script>
}